package controllers

import (
	"lottery/models"
	"strconv"
)

type OrderCtl struct {
	BaseCtl
}

func (o *OrderCtl) GetOrderList() {

	if !o.isLogin() {
		o.SetJson("请先登录！", nil)
		return
	}

	page_tmp := o.GetString("page", "0")
	show_type := o.GetString("type", "success")
	page, err := strconv.Atoi(page_tmp)
	if err != nil {
		o.SetJson(nil, err)
		return
	}
	userId := o.GetUserId()
	orderdata, err := models.GetOrderList(userId, page, 0, show_type)
	if err != nil {
		o.SetJson(nil, err)
		return
	}
	o.SetJson(orderdata, nil)
	return
}

func (o *OrderCtl) GetOrderResult() {
	if !o.isLogin() {
		o.SetJson("请先登录！", nil)
		return
	}

	orderId_str := o.GetString("orderId", "0")
	orderId, err := strconv.ParseInt(orderId_str, 10, 64)
	if err != nil {
		o.SetJson(nil, err)
		return
	}

	order, err := models.GetOrderResult(orderId)
	if err != nil {
		o.SetJson(nil, err)
		return
	}
	o.SetJson(order, nil)
	return
}
